import java.util.LinkedList;
import java.util.Queue;
public class BinaryTreeExercise {
    public static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;
        public  TreeNode(char val) {
            this.val = val;
        }
    }
    public static TreeNode createTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        return A;
    }
    public static void disPlay(TreeNode root) {
        System.out.println(root);
    }
    public static void levelOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while(!queue.isEmpty()) {
            //弹出放入队列cur
            TreeNode cur = queue.poll();
            System.out.print(cur.val+" ");
            if(cur.left != null) {
                //将左边放入队列
                queue.offer(cur.left);
            }
            if (cur.right != null) {
                //将右边放入队列
                queue.offer(cur.right);
            }
        }
    }
}